package com.hoongs.v1.entity;

import cn.hutool.core.bean.BeanUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Repository
public class CartProduct extends Cart {

    private String imageThumb;

    private String productName;

    private BigDecimal price;         // 商品价格

    private BigDecimal originalPrice;         // 商品原价（未优惠价格）

    private String size = "";         // 商品规格
    private String sizeDictValue = "";         // 商品规格字典

    public CartProduct fromProduct(Cart cart, Product product) {
        CartProduct cartProduct = new CartProduct();
        BeanUtil.copyProperties(cart, cartProduct);
        cartProduct.setProductName(product.getName());
        cartProduct.setImageThumb(product.getImageThumb());
        cartProduct.setPrice(product.getPrice());
        cartProduct.setOriginalPrice(product.getOriginalPrice() == null ? new BigDecimal(0) : product.getOriginalPrice());
        cartProduct.setSize(product.getSize());
        cartProduct.setSizeDictValue(product.getSizeDictValue());
        return cartProduct;
    }
}
